<template>
  <el-dialog title="编辑菜品" :visible.sync="visible" width="30%" @close="resetForm">
    <el-form :model="form" label-width="80px" ref="form">
      <el-form-item label="菜品名称" prop="name">
        <el-input v-model="form.name"></el-input>
      </el-form-item>
      <el-form-item label="价格" prop="price">
        <el-input v-model="form.price" type="number"></el-input>
      </el-form-item>
      <el-form-item label="描述" prop="description">
        <el-input v-model="form.description" type="textarea"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="submitForm">保存</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  data() {
    return {
      visible: false,
      form: {
        id: null,
        name: "",
        price: 0,
        description: "",
      },
    };
  },
  methods: {
    open(row) {
      this.form = { ...row };
      this.visible = true;
    },
    resetForm() {
      this.$refs.form.resetFields();
    },
    submitForm() {
      this.$emit("submit", this.form);
      this.visible = false;
    },
  },
};
</script>